﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="usermanager.aspx.cs" Inherits="GroundWater.Admin.usermanager" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
        <script language="javascript" src="../js/jquery.js" type="text/javascript"></script>
    <script language="javascript" src="../js/common.js" type="text/javascript"></script>
    <link media="all" href="../js/resources/_Common/Common.css" type=text/css rel=stylesheet />
<link media="all" href="../js/resources/_Loadding/Loadding.css" type=text/css rel=stylesheet />
<link media="all" href="../js/resources/_Panel/Panel.css" type=text/css rel=stylesheet />
<link media="all" href="../js/resources/_Button/Button.css" type=text/css rel=stylesheet />
<link media="all" href="../js/resources/_TextBox/TextBox.css" type=text/css rel=stylesheet />
</head>
<body>
    <form id="form1" runat="server"><asp:ScriptManager ID="sm" runat="server" />
    
    <asp:ObjectDataSource ID="odsUsers" runat="server" SelectMethod="GetAll" TypeName="GroundWater.BusinessActions.Users" DeleteMethod="DeleteById"  ondeleting="odsUsers_Deleting"  >
    <SelectParameters>
        <asp:Parameter Name="isStoredProc" Type="Boolean" DefaultValue="False" />
        <asp:Parameter Name="enableCache" Type="Boolean" DefaultValue="False" />
    </SelectParameters>
    <DeleteParameters>
        <asp:Parameter Name="id" Type="String" />
        <asp:Parameter Name="isStoredProc" Type="Boolean" DefaultValue="False" />
        <asp:Parameter Name="removeCache" Type="Boolean" DefaultValue="True" />
        <asp:Parameter Name="logical" Type="Boolean" DefaultValue="False" />
    </DeleteParameters>
    </asp:ObjectDataSource>
    <div style="width:96%;">
        <p style="font-weight:bold; font-family:Tahoma; margin-bottom:10px; "></p>
        <div class="grid">
            <div class="rounded">
                <div class="top-outer"><div class="top-inner"><div class="top">
                    <h2>用户管理 </h2>
                </div></div></div>
                <div class="mid-outer"><div class="mid-inner"><div class="mid">     
                
                    <!-- Content Goes Here! -->
                    <asp:UpdatePanel ID="updPanel" runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
                            <asp:GridView  ID="gvUsers" runat="server" DataSourceID="odsUsers" OnRowDataBound="RowDataBound" SkinID="PagingGridView" DataKeyNames="UserName">
                                <Columns>
                                    <asp:BoundField  HeaderText="用户名" DataField="UserName" SortExpression="UserName" HeaderStyle-CssClass="first" ItemStyle-CssClass="first" />
                                    <asp:BoundField  HeaderText="用户角色" DataField="UserRole"   SortExpression="UserRole" />
                                    <asp:BoundField  HeaderText="密码" DataField="Password"   SortExpression="Password" />
                                    <asp:BoundField  HeaderText="备注" DataField="Description"   SortExpression="Description" />
                                    <%--<asp:BoundField  HeaderText="备注" DataField="Description"     SortExpression="Description" DataFormatString="{0:c}"   ItemStyle-CssClass="money"  />--%>
                                    <asp:TemplateField><ItemTemplate><asp:LinkButton id="btnEdit" runat="server" CommandName="Select" OnClick="btnEdit_Click">编辑</asp:LinkButton></ItemTemplate></asp:TemplateField>
                                    <asp:CommandField ShowDeleteButton="true" DeleteText="删除" />
                                    <asp:TemplateField><ItemTemplate><asp:LinkButton id="btnEditAuth" runat="server" CommandName="Select" OnClick="btnEditAuth_Click">设置权限</asp:LinkButton></ItemTemplate></asp:TemplateField>
                                </Columns>
                            </asp:GridView>
                        </ContentTemplate>
                    </asp:UpdatePanel>                     
    
                </div></div></div>
            <div class="bottom-outer"><div class="bottom-inner">
            <div class="bottom"></div></div></div>                   
        </div>      
        </div>
    </div>
    
<!-- 面板内容 -->                
<div id="bodyPanel">

<asp:Panel ID="PopupPanel" runat="server" CssClass="x-pne" style="display:none; z-index:9999;  width:560px;">

<asp:UpdatePanel ID="updPnl" runat="server" UpdateMode="Conditional">
<ContentTemplate>

<asp:Button id="btnShowPopupHelper" runat="server" style="display:none" />
    <ajaxToolKit:ModalPopupExtender ID="mdlPopup" runat="server" 
    BehaviorID="editWell" 
    TargetControlID="btnShowPopupHelper" 
    PopupControlID="PopupPanel" 
    DropShadow="false"
    PopupDragHandleControlID="DragPanel"
    BackgroundCssClass="modalBackground"
    CancelControlID="btnClose" />

    <asp:Panel ID="DragPanel" runat="server" CssClass="corner-bg x-pne-lt x-pne-left">
    <div class="corner-bg x-pne-rt x-pne-right">
    <div class="corner-bg x-pne-t drag">
    <div class=x-pne-btn style="background-position: 0px 0px" onclick="$find('editWell').hide();" ></div>
    <div class="x-pne-caption font">编辑用户信息</div>
    </div>
    </div>
    </asp:Panel>
    
    <div>
    <div class="side-bg x-pne-l">
    <div class="side-bg x-pne-r">
    <div class="x-pne-c" style="WIDTH: 548px; HEIGHT: 238px">
    <div id="contentPanel"><!-- 控件实例 -->

    <div class=gbPanel>
        <%--<uc1:WellEditView ID="wellEditView" runat="server" />--%>
<table id="tblWell" class="font" style="width: 100%;">
    <tr>
        <td>用户帐号</td><td><asp:TextBox runat="server" CssClass="textField text-bg border-blur" id="txtUsername" type="text"  maxlength="16" /></td>
        <td>密码</td><td><asp:TextBox runat="server" CssClass="textField text-bg border-blur" id="txtPassword" type="text"  maxlength="16" /></td>
    </tr>
    <tr>
        <td>用户角色</td><td><asp:TextBox runat="server" CssClass="textField text-bg border-blur" id="txtUserRole" type="text"   /></td>
        <td>备注</td><td><asp:TextBox runat="server" CssClass="textField text-bg border-blur" id="txtDescription" type="text"   /></td>
    </tr>
</table>
    </div>

    <div class="gbPanel" style="margin-top:20px; text-align:center;">
    <table class="method-area1" style="margin:0 auto; text-align:left;">
    <tbody>
    <tr>
    <td style="padding-left:30px;">
        <div>
            <div class="btn-side btn-bg" style="background-position: 0% 0%"></div>
            <div class="btn-body btn-bg" style="background-position: 0px 168px; WIDTH: 60px"><asp:Button ID="btnOK" runat="server" Text="保  存" CssClass="font" OnClick="btnOK_Click" OnClientClick="return validateWell();" /></div><%----%>
            <div class="btn-side btn-bg" style="background-position: 0px 189px"></div>
        </div>
    </td>
    <td style="padding-left:30px;">
        <div>
            <div class="btn-side btn-bg" style="background-position: 0% 0%"></div>
            <div class="btn-body btn-bg" style="background-position: 0px 168px; WIDTH: 60px"><asp:Button ID="btnClose" runat="server" Text="取  消" CssClass="font" /></div>
            <div class="btn-side btn-bg" style="background-position: 0px 189px"></div>
        </div>
    </td>
    </tr>

    </tbody>
    </table>
    </div>


    </div>
    </div>
    </div>
    </div>
    
    <div class="corner-bg x-pne-lb x-pne-left">
        <div class="corner-bg x-pne-rb x-pne-right">
            <div class="corner-bg x-pne-b"></div>
        </div>
    </div>
    </div>
    
     </ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAdd" />
</Triggers>
 </asp:UpdatePanel>
</asp:Panel>

</div>
<!-- 面板内容结束 -->

<!-- 面板内容 -->                
<div id="authPanel">

<asp:Panel ID="authPopupPanel" runat="server" CssClass="x-pne" style="display:none; z-index:9999;  width:460px;">

<asp:UpdatePanel ID="udpAuthorization" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:HiddenField ID="txtMenus" runat="server" />
<asp:Button id="btnShowAuthHelper" runat="server" style="display:none" />
    <ajaxToolKit:ModalPopupExtender ID="mpeAuth" runat="server" 
    BehaviorID="authBehavior" 
    TargetControlID="btnShowAuthHelper" 
    PopupControlID="authPopupPanel"
    DropShadow="false"
    PopupDragHandleControlID="titlePanel"
    BackgroundCssClass="modalBackground"
    CancelControlID="btnCancel" />

    <asp:Panel ID="titlePanel" runat="server" CssClass="corner-bg x-pne-lt x-pne-left">
    <div class="corner-bg x-pne-rt x-pne-right">
    <div class="corner-bg x-pne-t drag">
    <div class=x-pne-btn style="background-position: 0px 0px" onclick="$find('authBehavior').hide();" ></div>
    <div class="x-pne-caption font drag">设置用户<asp:Literal ID="lblUsername" runat="server" EnableViewState="false"></asp:Literal>的权限</div>
    </div>
    </div>
    </asp:Panel>
    
    <div>
    <div class="side-bg x-pne-l">
    <div class="side-bg x-pne-r">
    <div class="x-pne-c" style="WIDTH: 448px; HEIGHT: 268px">
    <div id="Div2"><!-- 控件实例 -->

    <div class=gbPanel>
         <asp:CheckBoxList ID="cblMenus" runat="server" RepeatColumns="3"  EnableViewState="false"
             DataSourceID="odsMenus" DataTextField="Name" DataValueField="Id" 
             Font-Size="9pt" ondatabound="cblMenus_DataBound"></asp:CheckBoxList>
    <asp:ObjectDataSource ID="odsMenus" TypeName="GroundWater.BusinessActions.Users" SelectMethod="FetchMenusAll" runat="server" EnableCaching="True" CacheDuration="1" ></asp:ObjectDataSource>
    </div>

    <div class="gbPanel" style="margin-top:20px; text-align:center;">
    <table class="method-area1" style="margin:0 auto; text-align:left;">
    <tbody>
    <tr>
    <td style="padding-left:30px;">
        <div>
            <div class="btn-side btn-bg" style="background-position: 0% 0%"></div>
            <div class="btn-body btn-bg" style="background-position: 0px 168px; WIDTH: 60px"><input id="btnInverse" name="btnInverse" type="button" value="反  选" class="font" onclick="reserve();" /></div>
            <div class="btn-side btn-bg" style="background-position: 0px 189px"></div>
        </div>
    </td>
    <td style="padding-left:30px;">
        <div>
            <div class="btn-side btn-bg" style="background-position: 0% 0%"></div>
            <div class="btn-body btn-bg" style="background-position: 0px 168px; WIDTH: 60px"><asp:Button ID="btnSaveAuth" runat="server" Text="保  存" CssClass="font" OnClick="btnSaveAuth_Click"  /></div><%--OnClientClick="return validateWell();" --%>
            <div class="btn-side btn-bg" style="background-position: 0px 189px"></div>
        </div>
    </td>
    <td style="padding-left:30px;">
        <div>
            <div class="btn-side btn-bg" style="background-position: 0% 0%"></div>
            <div class="btn-body btn-bg" style="background-position: 0px 168px; WIDTH: 60px"><asp:Button ID="btnCancel" runat="server" Text="取  消" CssClass="font" /></div>
            <div class="btn-side btn-bg" style="background-position: 0px 189px"></div>
        </div>
    </td>
    </tr>

    </tbody>
    </table>
    </div>


    </div>
    </div>
    </div>
    </div>
    
    <div class="corner-bg x-pne-lb x-pne-left">
        <div class="corner-bg x-pne-rb x-pne-right">
            <div class="corner-bg x-pne-b"></div>
        </div>
    </div>
    </div>
     </ContentTemplate>
 </asp:UpdatePanel>
</asp:Panel>

</div>
<!-- 面板内容结束 -->


    
    <div style="margin-left:36px; margin-top:10px;"><asp:Button ID="btnAdd" runat="server" Text="添加用户" CssClass="BigButton" OnClick="btnAdd_Click" /></div>
    
<asp:updateprogress id="updateProgress" runat="server" DynamicLayout="true" DisplayAfter="200">
    <progresstemplate>
        <div id="progressBackgroundFilter"></div>
        <div id="processMessage">正在处理数据，请稍等...<br /><br /><img alt="Loading" src="../images/loading_16.gif" /></div>
    </progresstemplate>
</asp:updateprogress>
    
<script type="text/javascript">
//<![CDATA[
function validateWell() {
    var message = "";
    if (!notEmpty($get("txtUsername"))) {
        message += "用户帐号不能为空。\n";
    }
    if (!notEmpty($get("txtPassword"))) {
        message += "水密码不能为空。\n";
    }

    if (!notEmpty($get("txtUserRole"))) {
        message += "用户角色不能为空。\n";
    }
    if (message.length > 0) {
        alert(message);
        return false;
    }
    return true;
}


function pageLoad() {
    var mpe = $find('authBehavior');
    if (mpe) {
        mpe.add_showing(onShowing);
        //mpe.add_hiding(onHiding);
    }
}

function onShowing() {
    var txtMenus = $get('<%= txtMenus.ClientID %>');
    var roles = txtMenus.value;
    //if (roles.length == 0) return;
    var roleList = roles.split(",");
    var table = $get('<%= cblMenus.ClientID %>');
    var checkBoxes = table.getElementsByTagName('INPUT');
    for (var i = 0; i < checkBoxes.length; i++) {
        //var index = checkBoxes[i].name.substr(checkBoxes[i].name.indexOf("$", 0) + 1, 4); //checkBoxes[i].nextSibling.innerText
        var index = checkBoxes[i].parentNode.attributes["name"];
        if (checkBoxes[i].type == "checkbox" && Array.contains(roleList, index.value)) {
            checkBoxes[i].checked = true;
        }
        else {
            checkBoxes[i].checked = false;
        }
    }
}

function onHiding() {
    alert("onHiding");
    var roles = "";
    var txtMenus = $get('<%= txtMenus.ClientID %>');
    var table = $get('<%= cblMenus.ClientID %>');
    var checkBoxes = table.getElementsByTagName('INPUT');
    for (var i = 0; i < checkBoxes.length; i++) {
        if (checkBoxes[i].type == "checkbox" && checkBoxes[i].checked) {
            roles += checkBoxes[i].nextSibling.innerText + ",";
        }
    }

    if (roles.length > 0 && roles.charAt(roles.length - 1) === ",") roles = roles.substr(0, roles.length - 1);
    txtMenus.value = roles;
}

function reserve() {
    var table = $get('<%= cblMenus.ClientID %>');
    var checkBoxes = table.getElementsByTagName('INPUT');
    for (var i = 0; i < checkBoxes.length; i++) {
        if (checkBoxes[i].type == "checkbox") {
            checkBoxes[i].checked = !checkBoxes[i].checked;
        }
    }
}


//jQuery(document).ready(function() {
//    //    jQuery.each(jQuery("input[type=check]", "#cblMenus"), function() {
//    //        jQuery(this)
//    //    });
//    //alert(jQuery("input[type=checkbox]", "#cblMenus"));
//    document.getElementById("btnSelectAll").onclick = function() {
//        alert("ddd");
//        jQuery("input[type=checkbox]", "#cblMenus").each(function() {
//            this.checked = true;
//        });
//    }

//    jQuery("#btnSelectAll").click(function() {
//        alert("ddd");
//        jQuery("input[type=checkbox]", "#cblMenus").each(function() {
//            this.checked = true;
//        });
//    });

//    jQuery("#btnInverse").click(function() {
//        jQuery("input[type=checkbox]", "#cblMenus").each(function() {
//            if (this.checked)
//                this.checked = false;
//            else
//                this.checked = true;
//        });
//    });

//});
          
//]]>
</script>

<asp:Literal ID="lblJavaScript" EnableViewState="false" runat="server"></asp:Literal>
    </form>
</body>
</html>
